package com.ruandi.homework;

import com.ruandi.bean.Rectangle;

import java.math.BigDecimal;

public class Test3 {
    public static void main(String[] args) {
        Rectangle[] rectangle1 = new Rectangle[5];
        for (int i = 0; i < rectangle1.length; i++) {
            BigDecimal d1 = BigDecimal.valueOf(Math.random()*9+1);
            BigDecimal d2 = BigDecimal.valueOf(Math.random()*9+1);
            rectangle1[i] = new Rectangle(d1,d2);
        }
        for (int i = 0; i < rectangle1.length; i++) {
            rectangle1[i].getInfo();
        }
        System.out.println("--------------------------------------");
        for (int i = 1; i < rectangle1.length; i++) {
            for (int j = 0; j < rectangle1.length - i; j++) {
                if ((rectangle1[j].getArea()).doubleValue() > (rectangle1[j+1].getArea()).doubleValue()){
                    Rectangle temp = rectangle1[j];
                    rectangle1[j] = rectangle1[j+1];
                    rectangle1[j+1] = temp;
                }
            }
        }
        for (int i = 0; i < rectangle1.length; i++) {
            rectangle1[i].getInfo();
        }
    }
}
